package jmind.core.js;

import java.io.InputStream;

import javax.script.ScriptEngine;
import javax.script.ScriptEngineFactory;
import javax.script.ScriptEngineManager;




public  abstract class JavaScript {
	
	
	
	InputStream load(String name){
		return getClass().getClassLoader().getResourceAsStream(name);
	}
	
  
	/**
	 * 获得函数内容
	 * @param functionName
	 * @return
	 */
	 public abstract  String getFunctionContent(String functionName) ;
	
	 /**
	  * 执行函数
	  * @param name
	  * @return
	  */
	 public abstract Object eval(String name) ;


	 
	 public static void main(String[] args){
			ScriptEngineManager factory = new ScriptEngineManager();
			try {
				// create engine by name
				ScriptEngine engine = factory.getEngineByName ("JavaScript");
				System.out.println(engine);
				
			} catch (Exception e) {
				e.printStackTrace();
				
			}
		
			try {
				// create engine by name
				ScriptEngine engine2 = factory.getEngineByExtension ("js");
				System.out.println(engine2);
			} catch (Exception e) {
				e.printStackTrace();
			}
			try {
				// create engine by name
				ScriptEngine engine3 = factory.getEngineByMimeType ("application/javascript");
				System.out.println(engine3);
			} catch (Exception e) {
				e.printStackTrace();
			}
			
			try {
				ScriptEngine engine4 = factory.getEngineByName ("javascript");
				System.out.println(engine4);
			} catch (Exception e) {
				e.printStackTrace();
			}
			
			try {
				ScriptEngine engine5 = factory.getEngineByName ("js");
				System.out.println(engine5);
			} catch (Exception e) {
				e.printStackTrace();
			}
			
			
			System.out.println("----------------------------------------------------");
			for (ScriptEngineFactory available : factory.getEngineFactories()) {
			    System.out.println(available.getEngineName());
			    
			    System.out.println(available.getScriptEngine());
			    System.out.println(available.getExtensions());
			    System.out.println(available.getLanguageName());
			    System.out.println(available.getNames());
			    System.out.println(available.getMimeTypes());
			}
			
	 }

}
